package cn.sdhuijin.vms.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;

@Entity
@Table(name = "t_person")
public class Person extends IdEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@NotBlank(message = "姓名不能为空")
	@Column(updatable = false)
	private String name;
	@Length(max = 11, min = 11, message = "手机号码必须是11位。")
	@Column(unique = true)
	private String phone;
	@ManyToOne
	@JoinColumn(name = "master_id")
	private User master;
	@NotNull(message = "必须绑定卡号")
	@OneToOne(cascade = CascadeType.ALL)
	private Card card;
	@NotNull(message = "请选择机构")
	@ManyToOne
	@JoinColumn(name = "org_id")
	private Organization organization;

	@OneToMany(cascade = CascadeType.REMOVE, mappedBy = "person")
	public List<Leave> leaves = new ArrayList<Leave>();

	@OneToMany(cascade = CascadeType.REMOVE, mappedBy = "person")
	public List<PersonRecord> records = new ArrayList<PersonRecord>();

	public List<Leave> getLeaves() {
		return leaves;
	}

	public void setLeaves(List<Leave> leaves) {
		this.leaves = leaves;
	}

	public List<PersonRecord> getRecords() {
		return records;
	}

	public void setRecords(List<PersonRecord> records) {
		this.records = records;
	}

	public User getMaster() {
		return master;
	}

	public void setMaster(User master) {
		this.master = master;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public Organization getOrganization() {
		return organization;
	}

	public void setOrganization(Organization organization) {
		this.organization = organization;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Card getCard() {
		return card;
	}

	public void setCard(Card card) {
		this.card = card;
	}

}
